home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / comm2 / termsorc.lha / Extras / Source / term-source.lha / termPrint.c < prev    next >
C/C++ Source or Header  |  1995-09-26  |  24KB  |  1,142 lines

  1. /*
  2. **    termPrint.c
  3. **
  4. **    Printer control routines
  5. **
  6. **    Copyright © 1990-1995 by Olaf `Olsen' Barthel
  7. **        All Rights Reserved
  8. **
  9. **    :ts=4
  10. */
  11.  
  12. #include "termGlobal.h"
  13.  
  14.     /* PrintText(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR String,...):
  15.      *
  16.      *    Output a printf() style message.
  17.      */
  18.  
  19. BOOLEAN __stdargs
  20. PrintText(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR String,...)
  21. {
  22.     va_list    VarArgs;
  23.     LONG    Len;
  24.  
  25.     va_start(VarArgs,String);
  26.     VSPrintf(SharedBuffer,String,VarArgs);
  27.     va_end(VarArgs);
  28.  
  29.     if(ReqWindow)
  30.     {
  31.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  32.         {
  33.             *Error = 0;
  34.  
  35.             return(FALSE);
  36.         }
  37.     }
  38.     else
  39.     {
  40.         if(CheckSignal(SIG_BREAK))
  41.         {
  42.             *Error = 0;
  43.  
  44.             return(FALSE);
  45.         }
  46.     }
  47.  
  48.     Len = strlen(SharedBuffer) + 1;
  49.  
  50.     SetIoErr(0);
  51.  
  52.     strcat(SharedBuffer,"\n");
  53.  
  54.     if(Write(File,SharedBuffer,Len) < Len)
  55.     {
  56.         *Error = IoErr();
  57.  
  58.         return(FALSE);
  59.     }
  60.     else
  61.         return(TRUE);
  62. }
  63.  
  64.     /* PrintHeader(BPTR File,struct Window *ReqWindow,LONG *Error,ULONG Code):
  65.      *
  66.      *    Print a line header.
  67.      */
  68.  
  69. STATIC BOOLEAN __regargs
  70. PrintHeader(BPTR File,struct Window *ReqWindow,LONG *Error,ULONG Code,BOOLEAN Plain)
  71. {
  72.     STRPTR    String;
  73.     LONG    Len;
  74.  
  75.     String = LocaleString(Code);
  76.  
  77.     if(ReqWindow)
  78.     {
  79.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  80.         {
  81.             *Error = 0;
  82.  
  83.             return(FALSE);
  84.         }
  85.     }
  86.     else
  87.     {
  88.         if(CheckSignal(SIG_BREAK))
  89.         {
  90.             *Error = 0;
  91.  
  92.             return(FALSE);
  93.         }
  94.     }
  95.  
  96.     if(!Plain)
  97.         SPrintf(String = SharedBuffer,"\33[1m%s\33[0m",String);
  98.  
  99.     SetIoErr(0);
  100.  
  101.     Len = strlen(String);
  102.  
  103.     if(Write(File,String,Len) < Len)
  104.     {
  105.         *Error = IoErr();
  106.  
  107.         return(FALSE);
  108.     }
  109.  
  110.     return(TRUE);
  111. }
  112.  
  113.     /* PrintFileInformation():
  114.      *
  115.      *    Print information on a file.
  116.      */
  117.  
  118. BOOLEAN __regargs
  119. PrintFileInformation(BPTR File,struct Window *ReqWindow,LONG *Error,STRPTR Name,ULONG Flags)
  120. {
  121.     BOOLEAN Continue;
  122.  
  123.         /* Any special information to print along with the name? */
  124.  
  125.     if(Flags)
  126.     {
  127.         BPTR FileLock;
  128.  
  129.             /* Try to grip the file. */
  130.  
  131.         if(FileLock = Lock(Name,ACCESS_READ))
  132.         {
  133.             struct FileInfoBlock *FileInfo;
  134.  
  135.                 /* Allocate info buffer. */
  136.  
  137.             if(FileInfo = (struct FileInfoBlock *)AllocDosObject(DOS_FIB,TAG_DONE))
  138.             {
  139.                     /* How does it look like? */
  140.  
  141.                 if(Examine(FileLock,FileInfo))
  142.                 {
  143.                     UBYTE    DummyBuffer[300];
  144.                     STRPTR    Index;
  145.  
  146.                         /* Add the size. */
  147.  
  148.                     if(Flags & PRINT_SIZE)
  149.                         SPrintf(DummyBuffer,"%-25s %7ld",FilePart(Name),FileInfo -> fib_Size);
  150.                     else
  151.                         SPrintf(DummyBuffer,"%-25s",FilePart(Name));
  152.  
  153.                     Index = DummyBuffer;
  154.  
  155.                         /* Find the end of the string. */
  156.  
  157.                     while(*Index)
  158.                         Index++;
  159.  
  160.                         /* Add the protection bits. */
  161.  
  162.                     if(Flags & PRINT_BITS)
  163.                     {
  164.                         STATIC STRPTR    SetBits = "----aps",
  165.                                         ClrBits = "dewr---";
  166.  
  167.                         UBYTE TempString[10];
  168.  
  169.                         WORD i;
  170.  
  171.                         strcpy(TempString," -------");
  172.  
  173.                         for(i = 0 ; i < 7 ; i++)
  174.                         {
  175.                             if(FileInfo -> fib_Protection & (1L << i))
  176.                                 TempString[6 - i + 1] = SetBits[i];
  177.                             else
  178.                                 TempString[6 - i + 1] = ClrBits[i];
  179.                         }
  180.  
  181.                         strcpy(Index,TempString);
  182.  
  183.                         while(*Index)
  184.                             Index++;
  185.                     }
  186.  
  187.                         /* Add the creation date. */
  188.  
  189.                     if(Flags & PRINT_DATE)
  190.                     {
  191.                         UBYTE            Date[20],
  192.                                         Time[20];
  193.                         struct DateTime    DateTime;
  194.  
  195.                             /* Prepare for date conversion. */
  196.  
  197.                         DateTime . dat_Stamp    = FileInfo -> fib_Date;
  198.                         DateTime . dat_Format    = FORMAT_DOS;
  199.                         DateTime . dat_Flags    = DTF_SUBST;
  200.                         DateTime . dat_StrDay    = NULL;
  201.                         DateTime . dat_StrDate    = Date;
  202.                         DateTime . dat_StrTime    = Time;
  203.  
  204.                             /* Convert the date. */
  205.  
  206.                         if(DateToStr(&DateTime))
  207.                         {
  208.                             SPrintf(Index," %-9s %s",Date,Time);
  209.  
  210.                             while(*Index)
  211.                                 Index++;
  212.                         }
  213.                     }
  214.  
  215.                         /* Add the file comment. */
  216.  
  217.                     if(Flags & PRINT_COMMENT)
  218.                         SPrintf(Index,"\n: %s",FileInfo -> fib_Comment);
  219.  
  220.                     Continue = PrintText(File,ReqWindow,Error,"%s\n",DummyBuffer);
  221.                 }
  222.                 else
  223.                     Continue = FALSE;
  224.  
  225.                 FreeDosObject(DOS_FIB,FileInfo);
  226.             }
  227.             else
  228.                 Continue = FALSE;
  229.  
  230.             UnLock(FileLock);
  231.         }
  232.         else
  233.             Continue = FALSE;
  234.     }
  235.     else
  236.         Continue = PrintText(File,ReqWindow,Error,"%s\n",Name);
  237.  
  238.     return(Continue);
  239. }
  240.  
  241.     /* PrintEntry(BPTR File,struct Window *ReqWindow,LONG *Error,struct PhoneEntry *Entry):
  242.      *
  243.      *    Print information on the contents of a phonebook entry.
  244.      */
  245.  
  246. BOOLEAN __regargs
  247. PrintEntry(BPTR File,struct Window *ReqWindow,BOOLEAN Plain,LONG *Error,struct PhoneEntry *Entry,ULONG Flags)
  248. {
  249.     if(Plain)
  250.     {
  251.         if(!PrintText(File,ReqWindow,Error,"\n\"%s\" (%s)",Entry -> Header -> Name,Entry -> Header -> Number))
  252.             return(FALSE);
  253.     }
  254.     else
  255.     {
  256.         if(!PrintText(File,ReqWindow,Error,"\n\33[4m\"%s\" (%s)\33[0m",Entry -> Header -> Name,Entry -> Header -> Number))
  257.             return(FALSE);
  258.     }
  259.  
  260.     if(Flags & PRINT_COMMENT)
  261.     {
  262.         if(Entry -> Header -> Comment[0])
  263.         {
  264.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_COMMENT_TXT,Plain))
  265.                 return(FALSE);
  266.  
  267.             if(!PrintText(File,ReqWindow,Error,Entry -> Header -> Comment))
  268.                 return(FALSE);
  269.         }
  270.     }
  271.  
  272.     if(Flags & PRINT_USERNAME)
  273.     {
  274.         if(Entry -> Header -> UserName[0])
  275.         {
  276.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_USER_NAME_TXT,Plain))
  277.                 return(FALSE);
  278.  
  279.             if(!PrintText(File,ReqWindow,Error,Entry -> Header -> UserName))
  280.                 return(FALSE);
  281.         }
  282.     }
  283.  
  284.     if((Flags & PRINT_SERIAL) && Entry -> Config -> SerialConfig)
  285.     {
  286.         STATIC UBYTE Parities[] =
  287.         {
  288.             'N','E','O','M','S'
  289.         };
  290.  
  291.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_BAUD_RATE_TXT,Plain))
  292.             return(FALSE);
  293.  
  294.         if(LocaleBase)
  295.         {
  296.             if(!PrintText(File,ReqWindow,Error,"%lD",Entry -> Config -> SerialConfig -> BaudRate))
  297.                 return(FALSE);
  298.         }
  299.         else
  300.         {
  301.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> SerialConfig -> BaudRate))
  302.                 return(FALSE);
  303.         }
  304.  
  305.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_PARAMETERS_TXT,Plain))
  306.             return(FALSE);
  307.  
  308.         if(!PrintText(File,ReqWindow,Error,"%ld-%lc-%ld",Entry -> Config -> SerialConfig -> BitsPerChar,Parities[Entry -> Config -> SerialConfig -> Parity],Entry -> Config -> SerialConfig -> StopBits))
  309.             return(FALSE);
  310.  
  311.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_HANDSHAKING_TXT,Plain))
  312.             return(FALSE);
  313.  
  314.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SERIALPANEL_HANDSHAKING_NONE_TXT + Entry -> Config -> SerialConfig -> HandshakingProtocol)))
  315.             return(FALSE);
  316.  
  317.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DUPLEX_TXT,Plain))
  318.             return(FALSE);
  319.  
  320.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SERIALPANEL_DUPLEX_FULL_TXT + Entry -> Config -> SerialConfig -> Duplex)))
  321.             return(FALSE);
  322.  
  323.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_STRIP_BIT_TXT,Plain))
  324.             return(FALSE);
  325.  
  326.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> SerialConfig -> StripBit8)))
  327.             return(FALSE);
  328.  
  329.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_FLOW_CONTROL_TXT,Plain))
  330.             return(FALSE);
  331.  
  332.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> SerialConfig -> xONxOFF)))
  333.             return(FALSE);
  334.  
  335.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_SERIAL_DRIVER_TXT,Plain))
  336.             return(FALSE);
  337.  
  338.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_NAME_UNIT_TEMPLATE_TXT),Entry -> Config -> SerialConfig -> SerialDevice, + Entry -> Config -> SerialConfig -> UnitNumber))
  339.             return(FALSE);
  340.     }
  341.  
  342.     if((Flags & PRINT_MODEM) && Entry -> Config -> ModemConfig)
  343.     {
  344.         if(Entry -> Config -> ModemConfig -> ModemInit[0])
  345.         {
  346.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_MODEM_INIT_TXT,Plain))
  347.                 return(FALSE);
  348.  
  349.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemInit))
  350.                 return(FALSE);
  351.         }
  352.  
  353.         if(Entry -> Config -> ModemConfig -> ModemExit[0])
  354.         {
  355.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_MODEM_EXIT_TXT,Plain))
  356.                 return(FALSE);
  357.  
  358.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemExit))
  359.                 return(FALSE);
  360.         }
  361.  
  362.         if(Entry -> Config -> ModemConfig -> ModemHangup[0])
  363.         {
  364.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_HANG_UP_TXT,Plain))
  365.                 return(FALSE);
  366.  
  367.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> ModemHangup))
  368.                 return(FALSE);
  369.         }
  370.  
  371.         if(Entry -> Config -> ModemConfig -> DialPrefix[0])
  372.         {
  373.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_PREFIX_TXT,Plain))
  374.                 return(FALSE);
  375.  
  376.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> DialPrefix))
  377.                 return(FALSE);
  378.         }
  379.  
  380.         if(Entry -> Config -> ModemConfig -> DialSuffix[0])
  381.         {
  382.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_SUFFIX_TXT,Plain))
  383.                 return(FALSE);
  384.  
  385.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> ModemConfig -> DialSuffix))
  386.                 return(FALSE);
  387.         }
  388.  
  389.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_REDIAL_DELAY_TXT,Plain))
  390.             return(FALSE);
  391.  
  392.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MINUTE_SECOND_TEMPLATE_TXT),Entry -> Config -> ModemConfig -> RedialDelay / 60,Entry -> Config -> ModemConfig -> RedialDelay % 60))
  393.             return(FALSE);
  394.  
  395.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DIAL_TIMEOUT_TXT,Plain))
  396.             return(FALSE);
  397.  
  398.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MINUTE_SECOND_TEMPLATE_TXT),Entry -> Config -> ModemConfig -> DialTimeout / 60,Entry -> Config -> ModemConfig -> DialTimeout % 60))
  399.             return(FALSE);
  400.  
  401.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_AUTO_BAUD_TXT,Plain))
  402.             return(FALSE);
  403.  
  404.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> ModemConfig -> ConnectAutoBaud)))
  405.             return(FALSE);
  406.  
  407.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DROP_DTR_TXT,Plain))
  408.             return(FALSE);
  409.  
  410.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_DISABLED_TXT + Entry -> Config -> ModemConfig -> DropDTR)))
  411.             return(FALSE);
  412.     }
  413.  
  414.     if((Flags & PRINT_SCREEN) && Entry -> Config -> ScreenConfig)
  415.     {
  416.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_DISPLAY_MODE_TXT,Plain))
  417.             return(FALSE);
  418.  
  419.         if(!PrintText(File,ReqWindow,Error,GetModeName(Entry -> Config -> ScreenConfig -> DisplayMode)))
  420.             return(FALSE);
  421.  
  422.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_COLOUR_MODE_TXT,Plain))
  423.             return(FALSE);
  424.  
  425.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_SCREENPANEL_COLOUR_AMIGA_TXT + Entry -> Config -> ScreenConfig -> ColourMode)))
  426.             return(FALSE);
  427.     }
  428.  
  429.     if((Flags & PRINT_TERMINAL) && Entry -> Config -> TerminalConfig)
  430.     {
  431.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TERMINAL_EMULATION_TXT,Plain))
  432.             return(FALSE);
  433.  
  434.         if(Entry -> Config -> TerminalConfig -> EmulationMode == EMULATION_EXTERNAL)
  435.         {
  436.             if(!PrintText(File,ReqWindow,Error,"%s, \"%s\"",LocaleString(MSG_TERMINALPANEL_EMULATION_ANSI_VT102_TXT + Entry -> Config -> TerminalConfig -> EmulationMode),Entry -> Config -> TerminalConfig -> EmulationMode))
  437.                 return(FALSE);
  438.         }
  439.         else
  440.         {
  441.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_TERMINALPANEL_EMULATION_ANSI_VT102_TXT + Entry -> Config -> TerminalConfig -> EmulationMode)))
  442.                 return(FALSE);
  443.         }
  444.  
  445.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_FONT_TXT,Plain))
  446.             return(FALSE);
  447.  
  448.         if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_TERMINALPANEL_FONT_STANDARD_TXT + Entry -> Config -> TerminalConfig -> FontMode)))
  449.             return(FALSE);
  450.  
  451.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TEXT_COLUMNS_TXT,Plain))
  452.             return(FALSE);
  453.  
  454.         if(Entry -> Config -> TerminalConfig -> NumColumns < 20)
  455.         {
  456.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MAXIMUM_TXT)))
  457.                 return(FALSE);
  458.         }
  459.         else
  460.         {
  461.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> TerminalConfig -> NumColumns))
  462.                 return(FALSE);
  463.         }
  464.  
  465.         if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_TEXT_LINES_TXT,Plain))
  466.             return(FALSE);
  467.  
  468.         if(Entry -> Config -> TerminalConfig -> NumLines < 20)
  469.         {
  470.             if(!PrintText(File,ReqWindow,Error,LocaleString(MSG_PRINTPANEL_MAXIMUM_TXT)))
  471.                 return(FALSE);
  472.         }
  473.         else
  474.         {
  475.             if(!PrintText(File,ReqWindow,Error,"%ld",Entry -> Config -> TerminalConfig -> NumLines))
  476.                 return(FALSE);
  477.         }
  478.  
  479.         if(Entry -> Config -> TerminalConfig -> KeyMapFileName[0])
  480.         {
  481.             if(!PrintHeader(File,ReqWindow,Error,MSG_PRINTPANEL_KEYMAP_FILE_TXT,Plain))
  482.                 return(FALSE);
  483.  
  484.             if(!PrintText(File,ReqWindow,Error,"\"%s\"",Entry -> Config -> TerminalConfig -> KeyMapFileName))
  485.                 return(FALSE);
  486.         }
  487.     }
  488.  
  489.     return(TRUE);
  490. }
  491.  
  492.     /* PrintScreen(BPTR File,struct Window *ReqWindow,LONG *Error):
  493.      *
  494.      *    Print the contents of the screen, requires the raster
  495.      *    to be available.
  496.      */
  497.  
  498. BOOLEAN __regargs
  499. PrintScreen(BPTR File,struct Window *ReqWindow,LONG *Error)
  500. {
  501.     WORD     i,j;
  502.     UBYTE    *Buffer;
  503.  
  504.         /* Run down the lines... */
  505.  
  506.     for(i = 0 ; i <= LastLine ; i++)
  507.     {
  508.             /* Grab the line. */
  509.  
  510.         Buffer = &Raster[i * RasterWidth];
  511.  
  512.         j = LastColumn;
  513.  
  514.             /* Strip trailing spaces. */
  515.  
  516.         while(j >= 0 && Buffer[j] == ' ')
  517.             j--;
  518.  
  519.             /* Blank line? */
  520.  
  521.         if(j >= 0)
  522.         {
  523.             SetIoErr(0);
  524.  
  525.             if(Write(File,Buffer,j + 1) < j + 1)
  526.             {
  527.                 *Error = IoErr();
  528.  
  529.                 return(FALSE);
  530.             }
  531.         }
  532.  
  533.             /* Is printing to be aborted? */
  534.  
  535.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  536.         {
  537.             *Error = 0;
  538.  
  539.             return(FALSE);
  540.         }
  541.  
  542.             /* Add line terminator. */
  543.  
  544.         SetIoErr(0);
  545.  
  546.         if(Write(File,"\n",1) < 1)
  547.         {
  548.             *Error = IoErr();
  549.  
  550.             return(FALSE);
  551.         }
  552.  
  553.             /* Is printing to be aborted? */
  554.  
  555.         if(!SysReqHandler(ReqWindow,NULL,FALSE))
  556.         {
  557.             *Error = 0;
  558.  
  559.             return(FALSE);
  560.         }
  561.     }
  562.  
  563.     return(TRUE);
  564. }
  565.  
  566.     /* PrintClip(BPTR File,struct Window *ReqWindow,LONG *Error):
  567.      *
  568.      *    Print the contents of the clipboard.
  569.      */
  570.  
  571. BOOLEAN __regargs
  572. PrintClip(BPTR File,struct Window *ReqWindow,LONG *Error)
  573. {
  574.     LONG ClipError;
  575.  
  576.         /* Are we currently reading input from the
  577.          * clipboard? If so, close it.
  578.          */
  579.  
  580.     if(ClipInput)
  581.     {
  582.         CloseClip();
  583.  
  584.         ClipInput = ClipXerox = FALSE;
  585.     }
  586.  
  587.         /* Open the clipboard for reading. */
  588.  
  589.     if(ClipError = OpenClip(Config -> ClipConfig -> ClipboardUnit))
  590.     {
  591.         *Error = ERROR_OBJECT_NOT_FOUND;
  592.  
  593.         return(FALSE);
  594.     }
  595.     else
  596.     {
  597.         UBYTE    InputBuffer[257];
  598.         WORD    Len;
  599.  
  600.             /* Read clipboard contents. */
  601.  
  602.         while((Len = GetClip(InputBuffer,256,TRUE)) > 0)
  603.         {
  604.                 /* Are we to stop printing? */
  605.  
  606.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  607.             {
  608.                 *Error = 0;
  609.  
  610.                 CloseClip();
  611.  
  612.                 return(FALSE);
  613.             }
  614.             else
  615.             {
  616.                 SetIoErr(0);
  617.  
  618.                 if(Write(File,InputBuffer,Len) < Len)
  619.                 {
  620.                     *Error = IoErr();
  621.  
  622.                     CloseClip();
  623.  
  624.                     return(FALSE);
  625.                 }
  626.             }
  627.         }
  628.  
  629.         if(Len < 0)
  630.         {
  631.             if(SysReqHandler(ReqWindow,NULL,FALSE) == -2)
  632.             {
  633.                 SetIoErr(0);
  634.  
  635.                 if(Write(File,"\n",1) < 1)
  636.                     *Error = IoErr();
  637.  
  638.                 CloseClip();
  639.  
  640.                 return(FALSE);
  641.             }
  642.         }
  643.  
  644.         CloseClip();
  645.     }
  646.  
  647.     return(TRUE);
  648. }
  649.  
  650.     /* PrintBuffer(BPTR File,struct Window *ReqWindow,LONG *Error):
  651.      *
  652.      *    Print the contents of the text buffer.
  653.      */
  654.  
  655. BOOLEAN __regargs
  656. PrintBuffer(BPTR File,struct Window *ReqWindow,LONG *Error)
  657. {
  658.     BOOLEAN Continue = TRUE;
  659.     LONG i,Len;
  660.  
  661.     ObtainSemaphore(BufferSemaphore);
  662.  
  663.     if(BufferLines)
  664.     {
  665.         for(i = 0 ; i < Lines ; i++)
  666.         {
  667.             Len = BufferLines[i][-1];
  668.  
  669.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  670.             {
  671.                 *Error = 0;
  672.  
  673.                 Continue = FALSE;
  674.  
  675.                 break;
  676.             }
  677.  
  678.             if(Len)
  679.             {
  680.                 SetIoErr(0);
  681.  
  682.                 if(Write(File,BufferLines[i],Len) < Len)
  683.                 {
  684.                     *Error = IoErr();
  685.  
  686.                     Continue = FALSE;
  687.  
  688.                     break;
  689.                 }
  690.             }
  691.  
  692.             if(!SysReqHandler(ReqWindow,NULL,FALSE))
  693.             {
  694.                 *Error = 0;
  695.  
  696.                 Continue = FALSE;
  697.  
  698.                 break;
  699.             }
  700.  
  701.             SetIoErr(0);
  702.  
  703.             if(Write(File,"\n",1) < 1)
  704.             {
  705.                 *Error = IoErr();
  706.  
  707.                 Continue = FALSE;
  708.  
  709.                 break;
  710.             }
  711.         }
  712.     }
  713.     else
  714.         Continue = FALSE;
  715.  
  716.     ReleaseSemaphore(BufferSemaphore);
  717.  
  718.     return(Continue);
  719. }
  720.  
  721.     /* PrintSomething(BYTE Source):
  722.      *
  723.      *    Print the screen or the current contents of the clipboard.
  724.      */
  725.  
  726. VOID __regargs
  727. PrintSomething(BYTE Source)
  728. {
  729.     struct Window        *ReqWindow;
  730.     struct EasyStruct     Easy;
  731.     LONG                 Error = 0;
  732.  
  733.         /* Fill in the easy requester structure. */
  734.  
  735.     Easy . es_StructSize    = sizeof(struct EasyStruct);
  736.     Easy . es_Flags            = NULL;
  737.     Easy . es_Title            = (STRPTR)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  738.     Easy . es_GadgetFormat    = (STRPTR)LocaleString(MSG_PRINT_STOP_TXT);
  739.  
  740.     if(Source == PRINT_CLIP)
  741.         Easy . es_TextFormat = (STRPTR)LocaleString(MSG_PRINT_PRINTING_CLIP_TXT);
  742.     else
  743.         Easy . es_TextFormat = (STRPTR)LocaleString(MSG_PRINT_PRINTING_SCREEN_TXT);
  744.  
  745.         /* The requester is to be displayed while printing. */
  746.  
  747.     if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  748.     {
  749.         BPTR SomeFile;
  750.  
  751.             /* Add header information if printer channel is already open. */
  752.  
  753.         if(PrinterCapture)
  754.         {
  755.             LONG Len = strlen(LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT));
  756.  
  757.             if(Write(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT),Len) < Len)
  758.             {
  759.                 FreeSysRequest(ReqWindow);
  760.  
  761.                 ReqWindow = NULL;
  762.  
  763.                 Error = IoErr();
  764.             }
  765.             else
  766.                 SomeFile = PrinterCapture;
  767.         }
  768.         else
  769.         {
  770.                 /* Open printer channel. */
  771.  
  772.             if(!(SomeFile = Open("PRT:",MODE_NEWFILE)))
  773.             {
  774.                 FreeSysRequest(ReqWindow);
  775.  
  776.                 ReqWindow = NULL;
  777.  
  778.                 Error = IoErr();
  779.             }
  780.         }
  781.  
  782.             /* Everything fine so far? */
  783.  
  784.         if(!Error)
  785.         {
  786.             BOOLEAN Stopped;
  787.  
  788.                 /* Are we to print the screen? */
  789.  
  790.             if(Source == PRINT_SCREEN)
  791.                 Stopped = !PrintScreen(SomeFile,ReqWindow,&Error);
  792.             else
  793.                 Stopped = !PrintClip(SomeFile,ReqWindow,&Error);
  794.  
  795.                 /* Add a trailer if necessary. */
  796.  
  797.             if(PrinterCapture)
  798.             {
  799.                 if(!Error && !Stopped)
  800.                 {
  801.                     LONG Len;
  802.  
  803.                     SetIoErr(0);
  804.  
  805.                     Len = strlen(LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT));
  806.  
  807.                     if(Write(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT),Len) < Len)
  808.                         Error = IoErr();
  809.                 }
  810.             }
  811.             else
  812.             {
  813.                     /* Close the printer stream. */
  814.  
  815.                 if(!Close(SomeFile))
  816.                     Error = IoErr();
  817.             }
  818.         }
  819.  
  820.             /* Release the system requster. */
  821.  
  822.         if(ReqWindow)
  823.             FreeSysRequest(ReqWindow);
  824.  
  825.             /* Display the error code if necessary. */
  826.  
  827.         if(Error)
  828.         {
  829.             STRPTR ErrorString;
  830.  
  831.             if(Fault(Error,"",SharedBuffer,256))
  832.                 ErrorString = SharedBuffer;
  833.             else
  834.                 ErrorString = "???";
  835.  
  836.             MyEasyRequest(Window,LocaleString(MSG_PRINT_ERROR_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error,ErrorString);
  837.         }
  838.     }
  839. }
  840.  
  841.     /* PrintRegion(WORD Top,WORD Bottom):
  842.      *
  843.      *    Print the contents of a screen region.
  844.      */
  845.  
  846. VOID __regargs
  847. PrintRegion(WORD Top,WORD Bottom,BOOL FormFeed)
  848. {
  849.     BPTR     SomeFile;
  850.     WORD     i,j;
  851.     UBYTE    *Buffer;
  852.  
  853.     if(PrinterCapture)
  854.     {
  855.         LONG Len = strlen(LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT));
  856.  
  857.         if(Write(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_FOLLOWS_TXT),Len) < Len)
  858.         {
  859.             MyEasyRequest(Window,LocaleString(MSG_CONSOLE_ERROR_WRITING_TO_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  860.  
  861.             return;
  862.         }
  863.  
  864.         SomeFile = PrinterCapture;
  865.     }
  866.     else
  867.     {
  868.         if(!(SomeFile = Open("PRT:",MODE_NEWFILE)))
  869.         {
  870.             MyEasyRequest(Window,LocaleString(MSG_TERMMAIN_FAILED_TO_OPEN_PRINTER_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT));
  871.  
  872.             return;
  873.         }
  874.     }
  875.  
  876.     for(i = Top ; i < Bottom ; i++)
  877.     {
  878.         Buffer = &Raster[i * RasterWidth];
  879.  
  880.         j = LastColumn;
  881.  
  882.         while(j >= 0 && Buffer[j] == ' ')
  883.             j--;
  884.  
  885.         if(j >= 0)
  886.         {
  887.             SetIoErr(0);
  888.  
  889.             if(Write(SomeFile,Buffer,j + 1) < j + 1)
  890.             {
  891.                 FormFeed = FALSE;
  892.  
  893.                 break;
  894.             }
  895.         }
  896.  
  897.         SetIoErr(0);
  898.  
  899.         if(Write(SomeFile,"\n",1) < 1)
  900.         {
  901.             FormFeed = FALSE;
  902.  
  903.             break;
  904.         }
  905.     }
  906.  
  907.     if(PrinterCapture)
  908.     {
  909.         LONG Len = strlen(LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT));
  910.  
  911.         Write(PrinterCapture,LocaleString(MSG_CONSOLE_SCREEN_PRINTOUT_ENDING_TXT),Len);
  912.     }
  913.     else
  914.     {
  915.         if(FormFeed)
  916.             Write(SomeFile,"\f",1);
  917.  
  918.         Close(SomeFile);
  919.     }
  920. }
  921.  
  922.     /* PrintScreenGfx():
  923.      *
  924.      *    Print the window contents as graphics.
  925.      */
  926.  
  927. BOOLEAN
  928. PrintScreenGfx()
  929. {
  930.     LONG             Error;
  931.     struct MsgPort    *PrintPort;
  932.  
  933.         // Create the printer port
  934.  
  935.     if(PrintPort = CreateMsgPort())
  936.     {
  937.         struct IODRPReq *PrintRequest;
  938.  
  939.             // Create the rastport dump request
  940.  
  941.         if(PrintRequest = (struct IODRPReq *)CreateIORequest(PrintPort,sizeof(struct IODRPReq)))
  942.         {
  943.                 // Open the printer driver
  944.  
  945.             if(!OpenDevice("printer.device",0,PrintRequest,NULL))
  946.             {
  947.                 struct RastPort *RPort;
  948.  
  949.                     // Create a new rastport
  950.  
  951.                 if(NEW(RPort))
  952.                 {
  953.                     struct BitMap    *BitMap;
  954.                     WORD             Left,Top,
  955.                                      Width,Height;
  956.  
  957.                         // Initialize the rastport
  958.  
  959.                     InitRastPort(RPort);
  960.  
  961.                         // Keep these handy
  962.  
  963.                     Left    = Window -> LeftEdge    + Window -> BorderLeft;
  964.                     Top        = Window -> TopEdge        + Window -> BorderTop;
  965.                     Width    = Window -> Width        - (Window -> BorderLeft + Window -> BorderRight);
  966.                     Height    = Window -> Height        - (Window -> BorderTop + Window -> BorderBottom);
  967.  
  968.                     if(StatusWindow)
  969.                         Height -= StatusDisplayHeight;
  970.  
  971.                         // Allocate offscreen buffer to hold the window contents
  972.  
  973.                     if(BitMap = CreateBitMap(Width,Height,GetBitMapDepth(Window -> RPort -> BitMap),NULL,Window -> RPort -> BitMap))
  974.                     {
  975.                         struct EasyStruct     Easy;
  976.                         struct Window        *ReqWindow;
  977.  
  978.                             // Put the bitmap into the rastport
  979.  
  980.                         RPort -> BitMap = BitMap;
  981.  
  982.                             // Clear the bitmap
  983.  
  984.                         SetRast(RPort,0);
  985.  
  986.                             // Forbid any display changes
  987.  
  988.                         LockLayerRom(Window -> RPort -> Layer);
  989.  
  990.                             // Copy the window contents to the offscreen buffer
  991.  
  992.                         ClipBlit(Window -> RPort,Window -> BorderLeft,Window -> BorderTop,RPort,0,0,Width,Height,MINTERM_COPY);
  993.  
  994.                             // Permit display changes
  995.  
  996.                         UnlockLayerRom(Window -> RPort -> Layer);
  997.  
  998.                             // Wait for the bitmap to be transferred
  999.  
  1000.                         WaitBlit();
  1001.  
  1002.                             // Set up the print request
  1003.  
  1004.                         PrintRequest -> io_Command        = PRD_DUMPRPORT;
  1005.                         PrintRequest -> io_RastPort        = RPort;
  1006.                         PrintRequest -> io_ColorMap        = Window -> WScreen -> ViewPort . ColorMap;
  1007.                         PrintRequest -> io_Modes        = GetVPModeID(&Window -> WScreen -> ViewPort);
  1008.                         PrintRequest -> io_SrcWidth        = Width;
  1009.                         PrintRequest -> io_SrcHeight    = Height;
  1010.  
  1011.                             // Set up the abort requester
  1012.  
  1013.                         Easy . es_StructSize    = sizeof(Easy);
  1014.                         Easy . es_Flags            = NULL;
  1015.                         Easy . es_Title            = LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  1016.                         Easy . es_GadgetFormat    = LocaleString(MSG_GLOBAL_ABORT_GAD);
  1017.                         Easy . es_TextFormat    = LocaleString(MSG_PRINTING_SCREEN_TXT);
  1018.  
  1019.                             // Create the abort requester
  1020.  
  1021.                         if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  1022.                         {
  1023.                             ULONG Signals;
  1024.  
  1025.                                 // Everything is fine so far
  1026.  
  1027.                             Error = 0;
  1028.  
  1029.                                 // Start printing
  1030.  
  1031.                             BeginIO(PrintRequest);
  1032.  
  1033.                                 // Run until everything is done
  1034.  
  1035.                             FOREVER
  1036.                             {
  1037.                                     // Wait for an event
  1038.  
  1039.                                 Signals = Wait(PORTMASK(ReqWindow -> UserPort) | PORTMASK(PrintPort));
  1040.  
  1041.                                     // Is the printer finished?
  1042.  
  1043.                                 if(Signals & PORTMASK(PrintPort))
  1044.                                 {
  1045.                                         // Wait for the request to return and check for error
  1046.  
  1047.                                     switch(WaitIO(PrintRequest))
  1048.                                     {
  1049.                                         case PDERR_NOTGRAPHICS:
  1050.  
  1051.                                             Error = ERR_NO_GFX_OUTPUT;
  1052.                                             break;
  1053.  
  1054.                                         case PDERR_BADDIMENSION:
  1055.  
  1056.                                             Error = ERR_BAD_DIMENSION;
  1057.                                             break;
  1058.  
  1059.                                         case IOERR_OPENFAIL:
  1060.  
  1061.                                             Error = ERR_NO_PRINTER;
  1062.                                             break;
  1063.  
  1064.                                         case PDERR_INTERNALMEMORY:
  1065.                                         case PDERR_BUFFERMEMORY:
  1066.  
  1067.                                             Error = ERR_NO_MEM;
  1068.                                             break;
  1069.                                     }
  1070.  
  1071.                                     break;
  1072.                                 }
  1073.  
  1074.                                     // Did the user press the abort button?
  1075.  
  1076.                                 if(Signals & PORTMASK(ReqWindow -> UserPort))
  1077.                                 {
  1078.                                     if(!SysReqHandler(ReqWindow,NULL,FALSE))
  1079.                                     {
  1080.                                         AbortIO(PrintRequest);
  1081.  
  1082.                                         WaitIO(PrintRequest);
  1083.  
  1084.                                         break;
  1085.                                     }
  1086.                                 }
  1087.                             }
  1088.  
  1089.                                 // Close the requester
  1090.  
  1091.                             FreeSysRequest(ReqWindow);
  1092.                         }
  1093.                         else
  1094.                             Error = ERR_NO_MEM;
  1095.  
  1096.                             // Free the memory allocated for the bitmap
  1097.  
  1098.                         DeleteBitMap(BitMap);
  1099.                     }
  1100.                     else
  1101.                         Error = ERR_NO_MEM;
  1102.  
  1103.                         // Free the rastport
  1104.  
  1105.                     DISPOSE(RPort);
  1106.                 }
  1107.                 else
  1108.                     Error = ERR_NO_MEM;
  1109.  
  1110.                     // Close the printer driver
  1111.  
  1112.                 CloseDevice(PrintRequest);
  1113.             }
  1114.             else
  1115.                 Error = ERR_NO_PRINTER;
  1116.  
  1117.                 // Free the rastport dump request
  1118.  
  1119.             DeleteIORequest(PrintRequest);
  1120.         }
  1121.         else
  1122.             Error = ERR_NO_MEM;
  1123.  
  1124.             // Free the printer orpt
  1125.  
  1126.         DeleteMsgPort(PrintPort);
  1127.     }
  1128.     else
  1129.         Error = ERR_NO_MEM;
  1130.  
  1131.         // Return the result
  1132.  
  1133.     if(Error)
  1134.     {
  1135.         SetIoErr(Error);
  1136.  
  1137.         return(FALSE);
  1138.     }
  1139.     else
  1140.         return(TRUE);
  1141. }
  1142.